package com.lanchetech.redission;

import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {


    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.password}")
    private String password;

    private final int port = 6379;

    @Bean
    public Redisson redisson() {
        Config config = new Config();
        SingleServerConfig singleServerConfig = config.useSingleServer()
                .setAddress("redis://" + host + ":" + port);
        password = StringUtils.isBlank(password) ? null : password;
        singleServerConfig.setPassword(password);
        return (Redisson) Redisson.create(config);
    }

//    @Bean
//    public RedissonClient getRedisson() {
//        RedissonClient redisson = Redisson.create();
//        Config config = new Config();
//        config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password);
//        config.setCodec(new JsonJacksonCodec());
//        return Redisson.create(config);
//    }

}
